package com.wyy.springcloud.feign.controller;

import com.wyy.springcloud.pojo.Dept;
import com.wyy.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class DeptConsumerController {

//    @Autowired
//    RestTemplate restTemplate;

    @Resource
    private DeptClientService deptClientService;

    //private String baseUrl = "http://localhost:8001";
    private String baseUrl = "http://SPRINGCLOUD-PROVIDER-DEPT";

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept getDept(@PathVariable("id") Long id){
        return this.deptClientService.queryById(id);
    }

    @RequestMapping("/consumer/dept/get/all")
    public List<Dept> getDeptAll(){
        return deptClientService.queryAll();
    }

    @RequestMapping(value = "/consumer/dept/add")
    public boolean addDept(@RequestParam String dname){
        Dept dept = new Dept(dname);
        return deptClientService.addDept(dept);
    }

}
